﻿<%@ WebService Language="C#" Class="QhyAlarmWebService" %>

/*
 ***************************************************************************
 * Microsoft Visual C# .NET
 * 名称：       QhyAlarmWebService
 * 类型：       控制层
 * 功能说明：   发送短信息
 * 作者：       徐傲明
 * 创建日期：   2007/03/10
 * 修改日期     修改者      修改内容
 * 
 * 
 * ---
 ***************************************************************************
*/
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Collections;
using Shpm.App.Third.Dao;
using Shpm.App.Third.Bean;
using Shpm.App.Services.Dao;
using Shpm.App.Services.Bean;
using Shpm.App.Commons.Utils;
using Shpm.App.Commons.Db.Beans.Inp;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class QhyAlarmWebService : System.Web.Services.WebService
{

    [WebMethod]
    public void CheckAlarm() 
    {
        AlarmDao dao = new AlarmDao();
        UserAlarmActiveTelDao telDao = new UserAlarmActiveTelDao();
        
        //查询没有下班的员工的手机号码及其相关信息
        IList UserAlarmActiveTelList = telDao.GetUserAlarmActiveTel();

        //检索报警信息
        IList UserAlarmActiveList = dao.FindUserAlarmActive();

        IEnumerator enm = UserAlarmActiveList.GetEnumerator();
        
        while( enm.MoveNext() )
        {
            UserAlarmActiveBean alarmActiveBean = (UserAlarmActiveBean)enm.Current;

            string receiveNo = Convert.ToString(alarmActiveBean.ReceiveNo);

            IList shortList = ShortMessageUtil.GetShortMessage(InpShortMessageBean.TYPE_INFRARED_ALARM, receiveNo);

            if (shortList.Count > 0)
            {
                continue;
            }

            IList mobiles = new ArrayList();

            foreach (UserAlarmActiveTelBean dataBean in UserAlarmActiveTelList) 
            {
                if (string.IsNullOrEmpty(dataBean.HandSet)==false)
                {
                    mobiles.Add(dataBean.HandSet);
                }
            }

            string msg = string.Format("{0}{1}发生{2}报警, 请及时处理.", alarmActiveBean.UserID, alarmActiveBean.ZoneScript, alarmActiveBean.ZoneType);
            // 转换"#"为全角"＃",否则短信系统不能正确发送信息
            msg = msg.Replace("#", "＃");
            // 发送短信
            ShortMessageUtil.MT(mobiles, InpShortMessageBean.TYPE_INFRARED_ALARM, msg, receiveNo);
        }
    }
}

